using System.Collections;
using UnityEngine;

public class MsgLevelUp : MessageBase
{
	public Animation animationComp;

	public AnimationClip animText;

	public UILabel lbLevel;

	public bool isPlay;

	private int needLev;

	public override void SetText(string text)
	{
		needLev = int.Parse(text);
		if ((bool)lbLevel)
		{
			lbLevel.text = (needLev + 1).ToString();
		}
	}

	public override void StartMessage()
	{
		isPlay = true;
		base.gameObject.SetActive(true);
		if (ExpHUD.instance != null)
		{
			ExpHUD.instance.SetLevelLabel(needLev);
		}
		animationComp.clip = animText;
		animationComp.Play();
		StartCoroutine(WaitEndPlayAnimation());
	}

	public override void Wait()
	{
		base.gameObject.SetActive(false);
		if (ExpHUD.instance != null)
		{
			ExpHUD.instance.SetLevelLabel(needLev);
		}
	}

	private IEnumerator WaitEndPlayAnimation()
	{
		yield return new WaitForSeconds(1.65f);
		SetLevel();
		while (animationComp.isPlaying)
		{
			yield return new WaitForEndOfFrame();
		}
		isPlay = false;
		MessageManager.OnCompleteMessage(this);
	}

	private void SetLevel()
	{
		if (ExpHUD.instance != null)
		{
			ExpHUD.instance.SetLevelLabel(needLev + 1);
		}
	}
}
